<template>
  <div>
    <el-container>
      <el-main>
        <el-container class="parent-body">
          <el-header class="content-header">
            综合统计
            <div class="rightTop">
              <el-button @click="OutData()">导出数据</el-button>
              <el-button @click="all(1)" class="response">
                全部
              </el-button>
              <span />
              <el-button @click="thirty(2)" class="response"
                >最近30天</el-button
              >
              <span />
              <el-button @click="ninety(3)" class="response"
                >最近90天</el-button
              >

              <el-date-picker
                v-model="value1"
                :picker-options="pickerOptions"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="~"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              >
              </el-date-picker>
            </div>
          </el-header>
          <el-main>
            <el-header style="padding-top: 20px; font-size: 18px">
              <i class="el-icon-collection-tag"></i> 订单统计
            </el-header>
            <el-main>
              <el-form
                ref="orderStatistic"
                :model="orderStatistic"
                label-width="30%"
                disabled
              >
                <el-form-item label="销售总额" style="text-align: center">
                  <el-input
                    v-model="orderStatistic.saleTotal"
                    style="width: 60%"
                  >
                    <i slot="prefix" style="font-style:normal" class="unit">
                      ￥
                    </i>
                  </el-input>
                </el-form-item>
                <el-form-item label="有效订单总数" style="text-align: center">
                  <el-input
                    v-model="orderStatistic.validOrderNum"
                    style="width: 60%"
                  >
                  </el-input>
                </el-form-item>
                <el-form-item label="有效订单总额" style="text-align: center">
                  <el-input
                    v-model="orderStatistic.validOrderTotal"
                    style="width: 60%"
                  >
                    <i slot="prefix" style="font-style:normal" class="unit">
                      ￥
                    </i>
                  </el-input>
                </el-form-item>
                <el-form-item
                  label="无效订单总数(关闭或取消)"
                  style="text-align: center"
                >
                  <el-input
                    v-model="orderStatistic.invalidOrderNum"
                    style="width: 60%"
                  >
                  </el-input>
                </el-form-item>
                <el-form-item label="无效订单总额" style="text-align: center">
                  <el-input
                    v-model="orderStatistic.invalidOrderTotal"
                    style="width: 60%"
                  >
                    <i slot="prefix" style="font-style:normal" class="unit">
                      ￥
                    </i>
                  </el-input>
                </el-form-item>
                <el-form-item label="已成交订单总数" style="text-align: center">
                  <el-input
                    v-model="orderStatistic.successOrderNum"
                    style="width: 60%"
                  >
                  </el-input>
                </el-form-item>
                <el-form-item label="已成交订单总额" style="text-align: center">
                  <el-input
                    v-model="orderStatistic.successOrderTotal"
                    style="width: 60%"
                  >
                    <i slot="prefix" style="font-style:normal" class="unit">
                      ￥
                    </i>
                  </el-input>
                </el-form-item>
              </el-form>
            </el-main>
          </el-main>
        </el-container>
        <el-container class="parent-body">
          <el-main>
            <el-header style="padding-top: 20px; font-size: 18px">
              <i class="el-icon-collection-tag"></i> 会员统计
            </el-header>
            <el-main>
              <el-form
                ref="VIPStatistic"
                :model="VIPStatistic"
                label-width="30%"
                disabled
              >
                <el-form-item label="会员总数" style="text-align: center">
                  <el-input v-model="VIPStatistic.VIPAll" style="width: 60%">
                  </el-input>
                </el-form-item>
                <el-form-item label="有订单会员数" style="text-align: center">
                  <el-input
                    v-model="VIPStatistic.validVIPNum"
                    style="width: 60%"
                  >
                  </el-input>
                </el-form-item>
                <el-form-item label="会员订单总数" style="text-align: center">
                  <el-input
                    v-model="VIPStatistic.validVIPTotal"
                    style="width: 60%"
                  >
                  </el-input>
                </el-form-item>
                <el-form-item label="会员购物总额" style="text-align: center">
                  <el-input
                    v-model="VIPStatistic.VIPShopAll"
                    style="width: 60%"
                  >
                    <i slot="prefix" style="font-style:normal" class="unit">
                      ￥
                    </i>
                  </el-input>
                </el-form-item>
                <el-form-item label="会员购买率" style="text-align: center">
                  <el-input
                    style="width: 60%"
                    v-model="VIPStatistic.VIPPurchaseRate"
                  >
                    <i slot="suffix" style="font-style:normal" class="unit">
                      %
                    </i>
                  </el-input>
                </el-form-item>
                <el-form-item label="每会员订单数" style="text-align: center">
                  <el-input
                    style="width: 60%"
                    v-model="VIPStatistic.everyVIPOrderNum"
                  >
                  </el-input>
                </el-form-item>
                <el-form-item label="每会员购物额" style="text-align: center">
                  <el-input
                    style="width: 60%"
                    v-model="VIPStatistic.everyVIPShopAmount"
                  >
                    <i slot="prefix" style="font-style:normal" class="unit">
                      ￥
                    </i>
                  </el-input>
                </el-form-item>
              </el-form>
            </el-main>
          </el-main>
        </el-container>
        <el-container class="parent-body">
          <el-main>
            <el-header style="padding-top: 20px; font-size: 18px">
              <i class="el-icon-collection-tag"></i> 积分统计
            </el-header>
            <el-main>
              <el-form
                ref="integralStatistic"
                :model="integralStatistic"
                label-width="30%"
              >
                <el-form-item
                  label="总赠送消费积分(匠币)"
                  style="text-align: center"
                  disabled
                >
                  <el-input
                    v-model="integralStatistic.allHandselConsumeIntegral"
                    style="width: 60%"
                  >
                  </el-input>
                </el-form-item>
                <el-form-item
                  label="总赠送等级积分(成长值)"
                  style="text-align: center"
                  disabled
                >
                  <el-input
                    v-model="integralStatistic.allHandselLevelIntegral"
                    style="width: 60%"
                  >
                  </el-input>
                </el-form-item>
                <el-form-item label="操作" style="text-align: center">
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      @click="lookGood(scope.$index, integralStatistic)"
                      type="text"
                      >查看商品</el-button
                    >
                    <el-button
                      size="mini"
                      @click="lookOrder(scope.$index, integralStatistic)"
                      type="text"
                      >查看订单</el-button
                    >
                  </template>
                </el-form-item>
              </el-form>
            </el-main>
          </el-main>
        </el-container>
      </el-main>
    </el-container>
  </div>
</template>
<script>
export default {
  data() {
    return {
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit("pick", [start, end])
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
              picker.$emit("pick", [start, end])
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
              picker.$emit("pick", [start, end])
            }
          }
        ]
      },
      value1: [new Date(2018, 7, 1, 8, 40), new Date(2018, 7, 7, 8, 40)],
      orderStatistic: {
        saleTotal: 1000000.0,
        validOrderNum: 10000,
        validOrderTotal: 1000000.0,
        invalidOrderNum: 100,
        invalidOrderTotal: 10000.0,
        successOrderNum: 10000,
        successOrderTotal: 1000000.0
      },
      VIPStatistic: {
        VIPAll: 100000,
        validVIPNum: 10000,
        validVIPTotal: 10000,
        VIPShopAll: 1000000.0,
        VIPPurchaseRate: 0,
        everyVIPOrderNum: 0,
        everyVIPShopAmount: 0
      },
      integralStatistic: {
        allHandselConsumeIntegral: 100000,
        allHandselLevelIntegral: 100000
      }
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      this.VIPStatistic.VIPPurchaseRate =
        (this.VIPStatistic.validVIPNum / this.VIPStatistic.VIPAll) * 100
      this.VIPStatistic.everyVIPOrderNum =
        this.VIPStatistic.validVIPTotal / this.VIPStatistic.VIPAll
      this.VIPStatistic.everyVIPShopAmount =
        this.VIPStatistic.VIPShopAll / this.VIPStatistic.everyVIPOrderNum
      console.log(
        this.VIPStatistic.VIPPurchaseRate +
          "" +
          this.VIPStatistic.everyVIPOrderNum +
          "" +
          this.VIPStatistic.everyVIPShopAmount
      )
    },
    OutData() {
      alert("导出数据")
    },
    all(i) {
      var btn = document.getElementsByTagName("el-button") //获取按钮
      btn[i].onclick = function() {
        btn[i].style.backgroundColor = "blue"
        btn[i].style.color = "white"
      }
    },
    thirty(i) {
      var btn = document.getElementsByTagName("el-button") //获取按钮
      btn[i].onclick = function() {
        btn[i].style.backgroundColor = "blue"
        btn[i].style.color = "white"
      }
    },
    ninety(i) {
      var btn = document.getElementsByTagName("el-button") //获取按钮
      btn[i].onclick = function() {
        btn[i].style.backgroundColor = "blue"
        btn[i].style.color = "white"
      }
    },
    lookGood(index, list) {
      let routeData = this.$router.resolve({
        name: "lookGoodList",
        row: list
      })
      window.open(routeData.href, "_blank")
    },
    lookOrder(index, list) {
      let routeData = this.$router.resolve({
        name: "lookOrderList",
        row: list
      })
      window.open(routeData.href, "_blank")
    }
  }
}
</script>
<style scoped>
input {
  color: black;
}
</style>
